#include<bits/stdc++.h>
using namespace std;
const int N=8010;
int a[N],p[N];
int main(){
	freopen("build.in","r",stdin);
	freopen("build.out","w",stdout);
	int n,fl1,fl2,ans=1e9,sum;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		p[i]=i;
	}
	do{
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				fl1=fl2=0;
				for(int k=i+1;k<=j-1;k++){
					if(p[k]<p[i]&&p[k]<p[j]){
						fl1=1;
					}
					if(p[k]>p[i]&&p[k]>p[j]){
						fl2=1;
					}
				}
				if(fl1&&fl2){
					goto lass;
				}
			}
		}
		sum=0;
		for(int i=1;i<=n;i++){
			if(a[i]!=p[i]){
				sum++;
			}
		}
		ans=min(ans,sum);
		lass:;
	}while(next_permutation(p+1,p+1+n));
	printf("%d",ans);
}